package com.dqx.haoqiu.mvp.module.login;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.dqx.haoqiu.mvp.R;
import com.dqx.haoqiu.mvp.common.base.BaseActivity;
import com.dqx.haoqiu.mvp.module.login.dagger.DaggerLoginComponent;
import com.dqx.haoqiu.mvp.module.login.dagger.LoginModule;
import com.dqx.haoqiu.mvp.utils.Navigation;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.dqx.haoqiu.mvp.common.base.BaseApplication.getAppComponent;

/**
 * 登录页面
 */
public class LoginActivity extends BaseActivity<LoginPresenter> implements LoginContract.View {
    @BindView(R.id.et_mobilde)
    EditText etMobilde;
    @BindView(R.id.et_password)
    EditText etPassword;
    @BindView(R.id.btn_login)
    Button btnLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(newBase);
        DaggerLoginComponent.builder()
                .appComponent(getAppComponent())
                .loginModule(new LoginModule(this))
                .build().inject(this);
    }

    /**
     * 隐藏标题栏
     *
     * @return
     */
    @Override
    public boolean setTitleBarVisable() {
        return false;
    }

    /**
     * 登录成功
     */
    @Override
    public void loginSuccess() {
        Navigation.openUser(this);
        finish();
    }

    @OnClick({R.id.et_mobilde, R.id.et_password, R.id.btn_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_login:
                presenter.login(etMobilde.getText().toString(), etPassword.getText().toString());
                break;
        }
    }
}
